<template>
  <div ref="box">
    <v-nav :current="'1'" @EnData="EnData" @ChData="ChData"></v-nav>
    <!-- <banner :banners="sliderList" :swiperOption="swiperOption" v-if="timeShow"></banner> -->
    <slider :data="sliderList" :sliderType="'mosaic'" @currentIndex="getCurrentIndex" style="width: 100%;height: 600px;" ref="bannerH">
      <div style="width: 100%;height: 100%;position:relative;background-size: 100% 100%" v-for="(item, index) in sliderList" :key="item.id">
        <img :src="currentSrc" style="position:absolute;width: 100%;z-index:0;!important" ref="imgH">
        <mosaic
        style="position:absolute;z-index:20!important;"
        :img="item.src"
        :playTime="1000"
        :playPath="'right'"
        :playStart="'start'"
        v-if="currentIndex===index"
        ></mosaic>
      </div>
    </slider>
    <section class="sec1">
      <div>
        <!-- <img src="@/assets/home/1-title-en.png" alt="" class="item-title" v-if="!homeTitleImg"> -->
        <!-- <img src="@/assets/home/1-title.png" alt="" class="item-title" v-if="homeTitleImg"> -->
        <div class="new-title">
          <h1>{{homeText[9]}}</h1>
          <hr class="hr1">
          <hr class="hr2">
          <p>{{homeText[8]}}</p>
        </div>
        <div class="sec1-main">
          <div>
            <img src="@/assets/home/1.png" alt="">
          </div>
          <div style="width: 900px">
            <div>
              <div class="sec1-img">
                <div>
                  <img src="@/assets/home/2.png" alt="">
                </div>
                <div>
                  <img src="@/assets/home/3.png" alt="">
                </div>
              </div>
              <h1>{{EnChDataList.productionBase}}</h1>
              <div>
                <p>{{nineLimit}}<span @click="toMore">{{homeText[0]}} ></span></p>
                <a href="更多>"></a>
              </div>
            </div>
            <div style="padding-top: 33px;padding-bottom: 0px">
              <h1 style="margin-bottom: 15px;">{{EnChDataList.institute}}</h1>
              <div>
                <p>{{fourLimit}}<span @click="toMore">{{homeText[0]}} ></span></p>
                <a href="更多>"></a>
              </div>
              <div class="sec1-img" style="padding-bottom: 0">
                <div style="width: 225px">
                  <img src="@/assets/home/4.png" alt="">
                </div>
                <div style="width: 225px">
                  <img src="@/assets/home/5.png" alt="">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
    <section class="sec2">
      <div class="sec2-a p-content">
        <hr>
        <span>关于<span>倍特药业</span></span>
      </div>
      <div class="p-content sec2-main">
        <h1><span>AB</span>OUT</h1>
        <span>BRILLIANT</span>
        <div class="sec2-items" v-if="isAboutShow">
          <div>
            <h2>{{lists.about[0].name}}</h2>
            <div>
              <!-- <span>2007</span> -->
              <v-time :value="lists.about[0].value" class="growNum" :time="30"></v-time>
              <div><span>+</span><span>{{homeText[3]}}</span></div>
            </div>
            <hr>
          </div>
          <div>
            <h2>{{lists.about[1].name}}</h2>
            <div>
              <v-time :value="lists.about[1].value" class="growNum" :time="30"></v-time>
              <div><span>+</span><span>{{homeText[4]}}</span></div>
            </div>
            <hr>
          </div>
          <div>
            <h2>{{lists.about[2].name}}</h2>
            <div>
              <v-time :value="lists.about[2].value" class="growNum" :time="30"></v-time>
              <div><span>+</span><span>{{homeText[5]}}</span></div>
            </div>
            <hr>
          </div>
          <div style="background-color: transparent">
            <h2>{{lists.about[3].name}}</h2>
            <div>
              <v-time :value="lists.about[3].value" class="growNum" :time="lists.about[3].value"></v-time>
              <!-- <span>{{homeText[6]}}</span> -->
              <div><span>+</span><span>{{homeText[7]}}</span></div>
            </div>
            <hr>
          </div>
        </div>
      </div>
      <router-link :to="{name: 'jianjie'}" tag="div" class="more">
          <hr>
          <div>
            <div>
              <img src="@/assets/home/more.png" alt="">
            </div>
          </div>
      </router-link>
    </section>
    <section class="sec3">
      <div>
        <div class="title" style="margin-top: 47px;margin-bottom: 27px">
          <h1 style="margin-bottom: 44px">{{homeText[1]}}</h1>
        </div>
        <hr>
        <time-line :isScroll="isScroll" :timeDatao="timeDatao"
        :timeDatat="timeDatat"
        :timeLineData="timeLineData"
        v-if="isLichengShow"></time-line>
        <router-link :to="{name: 'licheng'}" tag="div" class="lc-more"><p><span>{{homeText[0]}}</span><img src="@/assets/home/lc-more.png" class="lc-more-icon"></p></router-link>
      </div>
    </section>
    <section class="sec4" v-if="isShowNews">
      <div>
        <div class="sec4-left">
          <div class="title" style="margin-bottom: 30px">
            <h1 style="color: #fff">{{homeText[2]}}</h1>
          </div>
          <router-link :to="{name: 'newsDetails', params: {id: this.id}}" tag="div" class="sec4-left-des">
            <div class="img-div">
              <img :src="newZxData.srczx" alt="">
            </div>
            <div class="left-des-info">
              <h2>{{newZxData.titlezx}}</h2>
              <p>{{newZxData.excerptzx}}</p>
            </div>
          </router-link>
        </div>
        <div class="sec4-right">
          <router-link :to="{name: 'news'}" tag="div" class="new-more"><span>查看更多</span><img src="@/assets/home/news-more.png" class="news-more-icon"></router-link>
          <div class="lists">
            <router-link :to="{name: 'newsDetails', params:{id: newzx.id}}" tag="div" class="list" v-for="newzx in lists.news" :key="newzx.id" @mouseenter.native="currentNew(newzx)">
              <div class="s4-time">
                <div>
                  <h3>{{newzx.time}}</h3>
                  <span>{{newzx.year}}</span>
                </div>
              </div>
              <div class="s4-info">
                <h3>{{newzx.post_title}}</h3>
                <p>{{newzx.post_excerpt}}</p>
              </div>
            </router-link>
            <div class="hr-b"></div>
          </div>
        </div>
      </div>
    </section>
    <v-footer></v-footer>
    <!-- <tab-line></tab-line> -->
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import vNav from '@/components/nav.vue'
import banner from '@/components/banner.vue'
import slider from '@/components/slider.vue'
import mosaic from '@/components/mosaic.vue'
// import slider from './sliderHome.vue'
import vFooter from '@/components/footer.vue'
import timeLine from '@/components/timeLine.vue'
import vTime from '@/components/time.vue'
import { getHomeData } from '@/services/api.js'
import { getHomeDataEn } from '@/services/api_en.js'
export default {
  name: 'home',
  data () {
    return {
      current: 1,
      num: 0,
      span: 500,
      max: 500,
      lists: [],
      newZxData: {},
      isScroll: false,
      timeDatao: null,
      timeDatat: null,
      timeLineData: [],
      value: 0,
      id: null,
      EnChDataList: {
        productionBase: '生产基地',
        institute: '研究院',
        lists: [
          {
            name: '先后投入数十亿元在全国范围内战略布局，逐步形成了以普药生产、原料药生产、冻干粉针生产、管制药生产、中药制剂生产和吸入气雾剂生产等'
          }
        ]
      },
      swiperOption: {},
      timeShow: true,
      four: null,
      nine: null,
      isAboutShow: false,
      isLichengShow: true,
      isShowNews: true,
      currentSrc: '',
      currentIndex: 0,
      sliderList: null
    }
  },
  computed: {
    ...mapGetters({
      'lang': 'lang',
      'homeTitleImg': 'homeTitleImg',
      'homeText': 'homeText'
    }),
    fourLimit () {
      if (!!this.four)
        return this.four.substring(0, 55) + '...'
      else
        return ''
    },
    nineLimit () {
      if (!!this.nine)
        return this.nine.substring(0, 55) + '...'
      else
        return ''
    }
  },
  components: {
    vNav,
    banner,
    vFooter,
    timeLine,
    vTime,
    mosaic,
    slider
  },
  methods: {
    getCurrentIndex (index) {
      // console.log(index)
      this.currentIndex = index
      if (this.sliderList[index - 1]) {
        this.currentSrc = this.sliderList[index - 1].src
      } else {
        this.currentSrc = this.sliderList[this.sliderList.length - 1].src
      }
    },
    toMore () {
      this.$router.push('/chanye')
    },
    getDocumentHeight () {
      this.scroll = document.documentElement.scrollTop || document.body.scrollTop
      if (this.scroll >= 700 && this.scroll <= 1600) {
        this.isAboutShow = true
      }
      if (this.scroll < 700 || this.scroll > 1600) {
        this.isAboutShow = false
      }
      if (this.scroll >= 1600 && this.scroll <= 2500) {
        this.isScroll = true
      } else {
        this.isScroll = false
      }
      // if (this.scroll < 20) {
      //   this.numScroll(500, 500, 0, 10)
      //   this.value = 600
      // }
      // if (this.scroll > 1620) {
      //   console.log(12)
      //   this.isScroll = true
      // }
    },
    numScroll (span, max, val, step) {
      let that = this
      that.num = val
      if (that.val < that.max) {
        setTimeout(function () {
          that.val += that.step
          that.numScroll(that.span, that.max, that.val, that.step)
        }, that.span)
      } else {
        this.num = that.max
      }
    },
    version () {
      // if (this.lang === 1) {
      //   console.log('中文版')
      //   this._getChList()
      //   this.isShowNews = true
      // }
      // if (this.lang === 2) {
      //   this._getEnList()
      //   this.isShowNews = false
      // }
      // this._getEnList()
      // this.isShowNews = false
      // console.log(222)
      let aa = this.getCookie('saveLang') || 1
      if (aa == 1) {
        this.lang = 1
        this._getChList()
        this.isShowNews = true
      }
      if (aa == 2) {
        this.lang = 2
        this._getEnList()
        this.isShowNews = false
      }
    },
    getCookie (name) {
      var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)")
      if(arr=document.cookie.match(reg))
        return unescape(arr[2])
      else
        return null
    },
    _getChList () {
      getHomeData().then((res) => {
        this.lists = res
        this.sliderList = res.banner
        // banner第一张图设置
        this.currentSrc = this.sliderList[0].src
        this.four = res.four
        this.nine = res.nine
        this.timeLineData = res.grow
        for (let k in res.news) {
          this.lists.news[k].post_title = res.news[k].post_title.substring(0, 20) + '...'
          this.lists.news[k].post_excerpt = res.news[k].post_excerpt.substring(0, 49) + '...'
        }
        this.newZxData = {
          titlezx: res.news[0].post_title.substring(0, 17) + '...',
          excerptzx: res.news[0].post_excerpt.substring(0, 49) + '...',
          srczx: res.news[0].src
        }
        this.timeDatao = res.grow[0]
        this.timeDatat = res.grow[1]
        this.timeShow = true
      })
    },
    _getEnList () {
      getHomeDataEn().then((res) => {
        this.lists = res
        this.sliderList = res.banner
        // banner第一张图设置
        this.currentSrc = this.sliderList[0].src
        this.four = res.four
        this.nine = res.nine
        this.timeLineData = res.grow
        this.timeDatao = res.grow[0]
        this.timeDatat = res.grow[1]
        this.timeShow = true
      })
    },
    EnData (res) {
      this._getEnList()
      this.EnChDataList = res
      this.isShowNews = false
    },
    ChData (res) {
      this._getChList()
      this.EnChDataList = res
      this.isShowNews = true
    },
    currentNew (current) {
      this.id = current.id
      let postTitle = current.post_title.substring(0, 17) + '...'
      let postExcerpt = current.post_excerpt.substring(0, 49) + '...'
      this.newZxData = {
        titlezx: postTitle,
        excerptzx: postExcerpt,
        srczx: current.src
      }
    }
  },
  // watch: {
  //   lang (newVal, oldVal) {
  //     if (newVal === 3) {
  //       this.reload()
  //     }
  //   }
  // },
  created () {
    window.addEventListener('scroll', this.getDocumentHeight)
    this.version()
    window.scrollTo(0, 0)
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  .new-title {
    position: relative;
    h1 {
      font-size: 32px;
      text-align: center;
      position: relative;
      width: 260px;
      margin: 0 auto;
      z-index: 2;
      &::after {
        content: "";
        width: 53px;
        height: 5px;
        background-color: #1a72da;
        position: absolute;
        top: 50%;
        left: -15%;
        transform: translateY(-50%)
      }
      &::before {
        content: "";
        width: 53px;
        height: 5px;
        background-color: #1a72da;
        position: absolute;
        top: 50%;
        left: 95%;
        transform: translateY(-50%)
      }
    }
    .hr1 {
      width: 470px;
      height: 1px;
      background-color: #ccc;
      position: absolute;
      left: 0;
      top: 20px;
      border: 0
    }
    .hr2 {
      width: 470px;
      height: 1px;
      background-color: #ccc;
      position: absolute;
      right: 0;
      top: 20px;
      border: 0
    }
    p {
      padding: 25px 0px;
      text-align: center;
      color: #666;
      line-height: 24px;
      font-size: 14px;
    }
  }
  .lc-more {
    width: 191px;
    height: 56px;
    background-color: #2859bb;
    border-radius: 27px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 1px;
    color: #fefefe;
    font-size: 18px;
    margin: 0 auto;
    margin-top: -57px;
    position: relative;
    cursor: pointer;
    .lc-more-icon {
      position: absolute;
      top: 50%;
      left: 140px;
      transform: translateY(-50%);
      animation: iconmore 2s infinite;
    }
  }
  @keyframes iconmore
  {
    from {
      left: 140px
    }
    to {
      left: 150px
    }
  }
  .amap-demo {
    height: 300px
  }
  .item-title {
    margin: 47px 0;
    display: block;
    margin-top: -15px;
  }
  .sec1 {
    height: 630px;
    background: url("/../../static/homeBg/s1-bg.png") no-repeat center;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    >div {
      width: 1200px;
    }
    .sec1-main {
      display: flex;
      justify-content: space-between;
      >div {
        display: flex;
        // >div {
        //   display: flex;
        //   justify-content: space-between;
        // }
        h1 {
          padding: 0 20px;
          font-size: 24px;
          letter-spacing: 2px;
          color: #2053b9;
          position: relative
        }
        h1:after {
          content: "";
          position: absolute;
          top: 37px;
          left: 20px;
          width: 100px;
          height: 2px;
          background-color: #2053b9
        }
        p {
          padding: 0 20px;
          font-size: 14px;
          line-height: 28px;
          letter-spacing: 1px;
          color: #949494;
          span {
            color: #2053b9;
            font-size: 14px;
            float: right;
            cursor: pointer
          }
        }
      }
      >div:nth-child(2) {
        box-shadow: 0px 12px 29px 0px rgba(65, 114, 212, 0.35);
        div {
          background-color: #fff;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          padding-bottom: 9px;
          overflow: hidden;
          width: 450px;
          // flex-grow: 1;
          img {
            // height: 100%;
          }
        }
        div:hover>img {
          transform: scale(1.1);
          transition: all 1s
        }
      }
      .sec1-img {
        display: flex;
        height: 188px;
        flex-direction: row!important;
      }
    }
  }
  .sec2 {
    height: 725px;
    background: url("/../../static/homeBg/s2-bg.png") no-repeat center;
    background-size: cover;
    position: relative;
    .sec2-a {
      position: absolute;
      left: 50%;
      top: 173px;
      transform: translateX(-50%);
      display: flex;
      align-items: center;
      width: 1202px;
      hr {
        border: 0;
        width: 320px;
        height: 2px;
        background-color: #fff;
        margin-right: 25px;
      }
      span {
        font-size: 32px;
        line-height: 48px;
        letter-spacing: 3px;
        color: #ffffff;
        span {
          color: #8ebb36;
        }
      }
    }
    .sec2-main {
      h1 {
        padding-top: 47px;
        padding-bottom: 30px;
        font-size: 72px;
        line-height: 48px;
        letter-spacing: 1px;
        color: #fff;
        span {
          font-size: 72px;
          line-height: 48px;
          letter-spacing: 1px;
          color: #8ebb36;
        }
      }
      span {
        font-size: 42px;
        line-height: 48px;
        letter-spacing: 4px;
        color: #ffffff;
      }
      .sec2-items {
        position: absolute;
        top: 266px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 1200px;
        >div {
          width: 270px;
          height: 270px;
          background-color: #1951bf;
          border: solid 1px rgba(255, 255, 255, 0.22);
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          h2 {
            font-size: 16px;
            letter-spacing: 1px;
            color: #ffffff;
          }
          hr {
            border: 0;
            width: 38px;
            height: 1px;
            background-color: #fff;
          }
          >div {
            margin: 33px 0;
            display: flex;
            justify-content: center;
            align-items: center;
            >span {
              margin-right: 27px;
              font-size: 58px;
              // line-height: 26px;
              letter-spacing: 5px;
              color: #ffffff;
            }
            div {
              display: flex;
              flex-direction: column;
              align-items: center;
              span {
                font-size: 18px;
                line-height: 26px;
                letter-spacing: 1px;
                color: #ffffff;
              }
            }
          }
        }
        >div:nth-child(2) {
          background-color: transparent;
        }
        >div:nth-child(3) {
          background: url("/../../static/homeBg/s2-3.png") no-repeat center;
          background-size: cover;
        }
        >div:nth-child(4) {
          background-color: transparent;
        }
      }
    }
    .more {
      position: absolute;
      bottom: 95px;
      width: 100%;
      hr {
        border: 0;
        width: 1200px;
        height: 1px;
        margin: 0 auto;
        background-color: rgba(255, 255, 255, 0.22);
        // display: none;
      }
      >div {
        width: 40px;
        height: 40px;
        background-color: #547bc9;
        margin: 0 auto;
        position: absolute;
        left: 50%;
        transform: translateX(-50%) rotate(45deg);
        margin-top: -20px;
        // display: flex;
        // align-items: center;
        // justify-content: center;
        z-index: 2;
        cursor: pointer;
        animation: iconmorepf 2s infinite;
        >div {
          width: 20px;
          height: 20px;
          background-color: #8ebb36;
          transform: rotate(90deg);
          margin: 0 auto;
          display: flex;
          // align-items: center;
          // justify-content: center;
          position: absolute;
          left: 24%;
          top: 24%;
          transform: translate(-50%, -50%);
          animation: iconmoreps 2s infinite;
          img {
            position: absolute;
            left: 50%;
            top: 10px;
            transform: translate(-50%, -50%) rotate(225deg);
            width: 52%
            // animation: iconmore 2s infinite;
          }
        }
      }
      @keyframes iconmorepf
      {
        from {
          z-index: 2;
          transform: translateX(-50%) rotate(45deg) scale(1)
        }
        to {
          z-index: 2;
          transform: translateX(-50%) rotate(45deg) scale(1.1)
        }
      }
      @keyframes iconmoreps
      {
        from {
          transform: rotate(90deg) scale(1)
        }
        to {
          transform: rotate(90deg) scale(1.1)
        }
      }
    }
  }
  .sec3 {
    height: 727px;
    background: url("/../../static/homeBg/s3-bg.png") no-repeat center;
    background-size: cover;
    position: relative;
    hr {
      width: 100%;
      border: 0;
      height: 1px;
      background-color: #2b64d5;
      position: absolute;
      top: 330px;
      transform: translateY(-50%)
    }
  }
  .sec4 {
    background: url("/../../static/homeBg/s4-bg.png") no-repeat center;
    background-size: cover;
    width: 100%;
    height: 723px;
    position: relative;
    overflow-x: hidden;
    .title {
      width: 100%
    }
    >div {
      width: 1200px;
      // max-width: 1200px;
      margin: 0 auto;
      // display: flex;
      >div {
        flex-grow: 1;
        width: 50%;
        height: 723px;
        display: flex;
        flex-direction: column;
        float: left;
        h1:after {
          background-color: #fff
        }
        .sec4-left-des {
          width: 448px;
          height: 470px;
          background-color: #ffffff;
          box-shadow: 0px 20px 19px 1px rgba(66, 99, 190, 0.47);
          cursor: pointer;
          .img-div {
            width: 448px;
            height: 254px;
            overflow: hidden;
            img {
              width: 100%;
              height: 100%
            }
          }
          .left-des-info {
            height: 142px;
            background-color: #fff;
            padding: 37px;
            h2 {
              font-size: 20px;
              line-height: 30px;
              letter-spacing: 0px;
              color: #333333;
              margin-bottom: 18px
            }
            p {
              font-size: 14px;
              line-height: 28px;
              letter-spacing: 0px;
              color: #666666;
            }
          }
        }
        .sec4-left-des:hover img {
          transform: scale(1.1);
          transition: all 1.5s
        }
      }
      .sec4-right {
        .new-more {
          font-size: 20px;
          line-height: 48px;
          letter-spacing: 2px;
          color: #666666;
          display: block;
          margin-top: 60px;
          margin-bottom: 83px;
          text-align: right;
          text-decoration: none;
          position: relative;
          cursor: pointer;
          padding-right: 20px
        }
        .news-more-icon {
          position: absolute;
          top: 50%;
          right: -14px;
          transform: translateY(-50%);
          animation: iconmoren 2s infinite;
        }
        @keyframes iconmoren
        {
          from {
            right: 14px;
          }
          to {
            right: 0px;
          }
        }
        .lists {
          position: absolute;
          top: 172px;
          width: 50%;
          .list {
            display: flex;
            height: 154px;
            background-color: transparent;
            .s4-time {
              // width: 177px;
              width: 159px;
              display: flex;
              flex-direction: column;
              border-right: 1px solid #e6e6e6;
              div {
                  display: flex;
                  flex-direction: column;
                  align-items: center;
                h3 {
                  font-size: 28px;
                  font-weight: normal;
                  font-stretch: normal;
                  line-height: 30px;
                  letter-spacing: 0px;
                  color: #2154b9;
                  padding-top: 34px;
                  margin-bottom: 13px
                }
                span {
                  font-size: 18px;
                  font-weight: normal;
                  font-stretch: normal;
                  line-height: 30px;
                  letter-spacing: 0px;
                  color: #666666;
                  text-indent: 23px;
                  // align-self: flex-end;
                }
              }
            }
            .s4-info {
              width: 423px;
              display: flex;
              flex-direction: column;
              padding-left: 15px;
              h3 {
                font-size: 20px;
                font-weight: normal;
                font-stretch: normal;
                font-weight: bolder;
                line-height: 30px;
                letter-spacing: 0px;
                color: #333;
                padding-top: 34px;
                margin-bottom: 13px
              }
              p {
                font-size: 14px;
                font-weight: normal;
                font-stretch: normal;
                line-height: 28px;
                letter-spacing: 0px;
                color: #666666;
              }
            }
          }
          .list:nth-child(1) {
            border-top: 1px solid #e6e6e6;
          }
          .list:hover {
            background-color: #fff;
            cursor: pointer;
          }
          .hr-b {
            width: 1px;
            height: 256px;
            background-color: #e6e6e6;
            position: absolute;
            top: 295px;
            left: 159px
          }
        }
      }
    }
  }
</style>
